package com.wave.gate.util;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.StrUtil;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.wave.gate.vo.GatePassSetVo;
import com.wave.gate.vo.GatePassWeightParamVo;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class GuavaCache {
    public static final Cache<String, String> STRING_CACHE = CacheBuilder.newBuilder()
            .initialCapacity(5)
            .maximumSize(1000)
            .build();
    //人脸机扫脸缓存
    public static final Cache<String, String> FACE_CACHE = CacheBuilder.newBuilder()
            .initialCapacity(5)
            .maximumSize(10000)
            .expireAfterWrite(1, TimeUnit.SECONDS)
            .build();
    //AI告警缓存
    public static final Cache<String, String> AI_CACHE = CacheBuilder.newBuilder()
            .initialCapacity(5)
            .maximumSize(1000)
            .expireAfterWrite(15, TimeUnit.SECONDS)
            .build();

    //5s内同一个告警，只缓存一次，此缓存作为校验
    public static final Cache<String, String> CHECK_MODELPATH_CACHE = CacheBuilder.newBuilder()
            .initialCapacity(5)
            .maximumSize(1000)
            .expireAfterWrite(5, TimeUnit.SECONDS)
            .build();

    //闸机模式
    public static final Cache<String, Integer> DOOR_MODE_CACHE = CacheBuilder.newBuilder()
            .initialCapacity(5)
            .maximumSize(1000)
            .build();

    //通道内是否有人集合
    public static final Cache<String, Integer> HASHUMAN_CACHE = CacheBuilder.newBuilder()
            .initialCapacity(5)
            .maximumSize(1000)
            .expireAfterWrite(15, TimeUnit.SECONDS)
            .build();

    //通道设置的ip集合缓存
    public static final Cache<String, GatePassSetVo> PASSSET_CACHE = CacheBuilder.newBuilder()
            .initialCapacity(5)
            .maximumSize(10)
            .build();

    //手机/token重量误差集合
    public static final Cache<String, List<GatePassWeightParamVo>> MOBILE_TOKEN_WEIGHTLIST_CACHE = CacheBuilder.newBuilder()
            .initialCapacity(5)
            .maximumSize(10)
            .build();

    //AI尾随告警缓存，用来阻止太多尾随语音告警
    public static final Cache<String, String> AI_WS_CACHE = CacheBuilder.newBuilder()
            .initialCapacity(5)
            .maximumSize(1000)
            .expireAfterWrite(3, TimeUnit.SECONDS)
            .build();

    //通道内是否有人集合
    public static final Cache<String, String> DEVICETYPE_CACHE = CacheBuilder.newBuilder()
            .initialCapacity(5)
            .maximumSize(1000)
            .expireAfterWrite(15, TimeUnit.SECONDS)
            .build();

    //危险区域闯入
    public static final Cache<String, String> AI_WX_CACHE = CacheBuilder.newBuilder()
            .initialCapacity(5)
            .maximumSize(1000)
            .expireAfterWrite(3, TimeUnit.SECONDS)
            .build();

    public static void main(String[] args) throws Exception {
        /*CHECK_MODELPATH_CACHE.put("aa","aaaa");
        CHECK_MODELPATH_CACHE.put("bb","bbbb");
        System.out.println(CHECK_MODELPATH_CACHE.asMap());
        CHECK_MODELPATH_CACHE.invalidateAll(Arrays.asList("aa","bb"));
        //TimeUnit.SECONDS.sleep(3);
        System.out.println(CHECK_MODELPATH_CACHE.asMap());
        TimeUnit.SECONDS.sleep(2);
        System.out.println(CHECK_MODELPATH_CACHE.asMap());*/
        System.out.println(UUID.fastUUID().toString().replace("-", ""));

    }
}
